#ifndef MYDEVICE_H
#define MYDEVICE_H


#include "pinctrl.h"
#include "soc_osal.h"
#include "uart.h"
#include "watchdog.h"
#include "osal_debug.h"
#include "cmsis_os2.h"
#include "app_init.h"
#include "gpio.h"
#include <stdint.h> // 确保有 stdint.h 头文件支持类型定义


#define SLE_LOG                 "[SLE]"
#define RGB_LOG                 "[RGB]"
#define FAN_LOG                 "[FAN]"
#define WATER_LOG               "[WATER]"
#define UART_LOG                "[UART]"
#define LORA_LOG                "[LORA]"
#define SHT3X_LOG               "[SHT3X]"
#define XZM_LOG                 "[XZM]"

#define UART_BAUDRATE                      115200
#define UART_DATA_BITS                     3
#define UART_STOP_BITS                     1
#define UART_PARITY_BIT                    0
#define UART_TRANSFER_SIZE                 512

#define NUM_DEVICES                        4
#define VREF 3300.0f // 参考电压（mV）
enum state {
    UNKNOW,
    SLEEP,    
    CONNECTING,
    WAIT,
    READY,
    RUNNING,
    STOP
};
typedef struct SensorData
{
    char ligBuffer[10];
    char humidity[10];
    char temperature[10];
    char soilHum[10];
    char uv[10];
    char rain[10];
    char co2[10];
    int id;
}SensorData;

typedef struct {
    char fanFlag[2];       // 存储 "0" 或 "1"
    char waterFlag[2];
    char sunFlag[2];
    char switchFlag[2];
    char colorNum[3][4];   // 存储 r, g, b 值，每个值最多 2 个字符加一个空字符
} ControlState;


typedef struct {
    int deviceId;             // 设备的唯一标识符
    char deviceName[32];      // 设备名称（可选）
    ControlState controlState; // 设备状态
} TargetDevice;

// 定义最大设备数量和设备信息结构体
#define MAX_DEVICES 4
// TargetDevice devices[NUM_DEVICES];
// 创建目标设备数组
// extern SensorData othData;
// typedef unsigned int uint16_10t;
void uart_gpio_init(uint16_t uart_bus,uint16_t uart_tx,uint16_t uart_rx );
void uart_init_config(uint16_t uart_bus,uint16_t uart_tx,uint16_t uart_rx,uart_buffer_config_t* buff_config);


void light_data_treating(uint8_t ch, uint32_t *buffer, uint32_t length, bool *next,SensorData* Data);
void soilHum_data_treating(uint8_t ch, uint32_t *buffer, uint32_t length, bool *next,SensorData* Data);
void uv_data_treating(uint8_t ch, uint32_t *buffer, uint32_t length, bool *next,SensorData* Data);
void rain_data_treating(uint8_t ch, uint32_t *buffer, uint32_t length, bool *next,SensorData* Data);
void init_control_state(ControlState *state);
void init_water(void);
void water_control(bool flag);
void init_fan(void);
void set_fan_in(void);
void set_fan_out(void);
void set_fan_stop(void);
void control(ControlState* conData);
void print_sensor_data(SensorData *data);
#endif 